package com.itheima.tlias84.mapper;

import com.itheima.tlias84.Po.SelectClazzPageParam;
import com.itheima.tlias84.Po.SelectStudentPageParam;
import com.itheima.tlias84.Po.UpdateStudentViolationParam;
import com.itheima.tlias84.controller.SelectStudentCountDTO;
import com.itheima.tlias84.dto.SelectStudentDTO;
import com.itheima.tlias84.dto.SelectStudentDegreeDataDTO;
import com.itheima.tlias84.entity.Student;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface StudentMapper {
    /**
     * 根据id查询学生
     * @param id
     * @return
     */
    SelectStudentDTO selectStudentById(@Param("id") Integer id);

    //分页查询学生
    List<SelectStudentDTO> selectStudentByPage(@Param("p") SelectStudentPageParam param);

    /**
     * 新增学生信息
     */
    @Insert("insert into student(name,no,gender,phone,id_card,is_college,address,degree,graduation_date,clazz_id,update_time,create_time)"
            + "values(#{s.name},#{s.no},#{s.gender},#{s.phone},#{s.idCard},#{s.isCollege},#{s.address},#{s.degree},#{s.graduationDate},#{s.clazzId},#{s.updateTime},#{s.createTime})")
    int insertStudent(@Param("s") Student student);

    /**
     * 根据id删除学生信息
     */
    @Delete("delete from student where id=#{d}")
    int deleteById(@Param("d") Integer id);

    /**
     *修改学生信息
     */
    @Update("update student set name=#{s.name},no=#{s.no},gender=#{s.gender},phone=#{s.phone},id_card=#{s.idCard}," +
            "is_college=#{s.isCollege},address=#{s.address},degree=#{s.degree},graduation_date=#{s.graduationDate}," +
            "clazz_id=#{s.clazzId},violation_count=#{s.violationCount},violation_score=#{s.violationScore},update_time=#{s.updateTime},create_time=#{s.createTime} where id=#{s.id}")
    int updateStudentById(@Param("s") Student student);

    /**
     * 根据姓名查询学生
     * @param student
     * @return
     */
    @Select ("select id,name from student where name=#{name}")
    SelectStudentDTO selectStudentByName(@Param("name") String student);

    /**
     *更新学生违纪扣分
     */
    @Update("update student set violation_count=#{s.violationCount},violation_score=#{s.violationScore},update_time=#{s.updateTime} where id=#{s.id}")
    int updateStudentViolation(@Param("s") UpdateStudentViolationParam param);

    /**
     * 学生学历统计
     */
    List<SelectStudentDegreeDataDTO> selectStudentDegreeData();

    /**
     *统计每个班级的人数信息
     */
    List<SelectStudentCountDTO>selectStudentCount();

    /**
     *根据班级id查询学生表
     */
    List<SelectStudentDTO>selectStudentByClazzId(@Param("clazzId") Integer id);




}